<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增纪检风采')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-arrange-add">

            <input id="userIds" name="userIds" class="form-control" type="hidden">
            <input id="status" name="status" class="form-control" type="hidden">

            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">标题：</label>
                <div class="col-sm-8">
                    <input name="demeanorTitle" class="form-control" type="text" required>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label is-required">分类：</label>
                <div class="col-sm-8">
                    <select name="demeanorCategory" class="form-control m-b" th:with="type=${@dict.getType('demeanor_category')}" readonly>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${demeanorCategory == dict.dictValue}" ></option>
                    </select>
                </div>
            </div>



            <div class="form-group">
                <label class="col-sm-3 control-label">封面图片：</label>
                <div class="col-sm-8">
                    <input id="coverPhoto" name="coverPhoto" type="hidden" required>
                    <div class="file-loading">
                        <input id="file-upload-pic" name="file" class="form-control file-upload" type="file" data-show-preview="false" multiple>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">附件：</label>
                <div class="col-sm-8">
                    <input id="attachments" name="attachments" type="hidden">
                    <div class="file-loading">
                        <input id="file-loading-video" name="file" class="form-control file-upload" type="file" data-show-preview="false" multiple>
                    </div>
                </div>
            </div>

            <div class="form-group">    
                <label class="col-sm-3 control-label">摘要：</label>
                <div class="col-sm-8">
                    <input name="summary" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">关键标签：</label>
                <div class="col-sm-8">
                    <input name="keyTags" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">内容：</label>
                <div class="col-sm-8">
                    <input type="hidden" class="form-control" name="demeanorContent">
                    <div class="summernote" id="demeanorContent"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input name="remark" class="form-control" type="text">
                </div>
            </div>
        </form>
        <div class="row">
            <div class="col-sm-offset-5 col-sm-10">
                <button type="button" class="btn btn-sm btn-success" onclick="submitHandler('1')"><i class="fa fa-plus"></i>暂 存</button>&nbsp;
                <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler('2')"><i class="fa fa-check"></i>发 布</button>&nbsp;
                <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭</button>
            </div>
        </div>

    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "demeanor/arrange"

        $("#form-arrange-add").validate({
            focusCleanup: true
        });
        // ., .docx, .xls, .xlsx, .pdf
        // 附件上传初始化
        $(function(){
            let demeanorCategory = [[*{demeanorCategory}]];
            initUploadFileInfo("coverPhoto", "file-upload-pic", [], "");

            if (demeanorCategory == 4) {
                initUploadFileInfo("attachments", "file-loading-video", ["mp4"], "");
            } else {
                initUploadFileInfo("attachments", "file-loading-video", [], "");

            }

            // initUploadFileInfo("attachments", "file-upload", [], "");
        })

        // 编辑器上传文件
        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function (result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function (error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }


        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-arrange-add').serialize());
            }
        }

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });

        function submitHandler(status) {
            if ($.validate.form()) {
                $('#status').val(status)
                $.operate.save(prefix + "/add", $('#form-arrange-add').serialize());
            }
        }



    </script>
</body>
</html>